package com.wl.mr.speak;

import org.apache.hadoop.mapreduce.Reducer;

import javax.xml.soap.Text;
import java.io.IOException;

public class SpeakReducer extends Reducer<Text,SpeakBean,Text,SpeakBean> {
    @Override
    protected void reduce(Text key, Iterable<SpeakBean> values, Context context) throws IOException, InterruptedException {

        Long selfDurationSum = 0L;
        Long thirdDurationSum = 0L;
        for (SpeakBean value : values) {
            final Long selfDuration = value.getSelfDuration();
            final Long thirdDuration = value.getThirdDuration();
            selfDurationSum += selfDuration;
            thirdDurationSum += thirdDuration;
        }
        SpeakBean v =new SpeakBean(selfDurationSum,thirdDurationSum,key.toString());
        context.write(key,v);
    }
}
